<?php


namespace app\api\controller;


use aliyun\Sms;
use app\api\services\JwtService;
use app\api\services\QrcodeService;
use app\jobs\TestJob;
use think\Exception;
use think\facade\Lang;

class Index extends Base
{
    public function sendSms()
    {
        try{
            $sms = new Sms();
            $res = $sms->sendSms('15921324164' , '666666');
            return $this->returnResult(200 , '' ,$res);
        }catch (Exception $e){
            return $this->returnResult(500 , $e->getTrace());
        }

    }
    public function test($param = [])
    {
        $name = input('name');
        $data = Lang::get($name);
        return $this->returnResult(200,'',$data);
        // 抛出404异常
//        abort(404, '页面异常');
//        return 5/0;
//        return $this->returnJson(1, '测试Index/test');
    }

    public function getToken()
    {
        $token = JwtService::createJwt(1);
        return $this->returnResult(200 , '' , ['token' => $token]);
    }

    public function checkToken()
    {
        $jwt = input('jwt');
        $token = JwtService::verifyJwt($jwt);
        return $this->returnResult($token['code'] , $token['msg'] , ['token' => $token['data']]);
    }

    // 测试
    public function a()
    {
        $q = new QrcodeService();
        $data['type'] = 'scan';
        $data['data']['store_id'] = 5;
        $data['data']['store_name'] = '扫码测试基站门店';
        $ret = $q->makeQrcode($data);
        return  $ret;

        $key1 = TestJob::dispatch(['Index/a-无延迟队列', date('Y-m-d H:i:s')]);
        $key2 = TestJob::dispatchSece(10, ['Index/a-延迟10s队列', date('Y-m-d H:i:s')]);
        return $this->returnResult(200 , '测试队列' , [$key1 , $key2]);
    }
    // 测试消费b
    public function b()
    {
        $q = new QrcodeService();
        $fileName = date('YmdHis') . '_store2.png';
        var_dump($q->makeXcxUnlimitQrcode('pages/index/index' , 'store_id=2' ,$fileName ));
        die;

        $testJob = new TestJob();
        $res = $testJob->doJob(['测试666']);
        var_dump($res);
    }
    // 获取用户-中间件-校验token
    public function getUser()
    {
        $param = $this->request->param();
        event('testEvent',['uid'=>$this->request->uid,'time'=>date('Y-m-d H:i:s')]);// 触发事件,传递参数
        return $this->returnResult(200, '获取成功', [$param , $this->request->uid]);
    }
}